home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1996 Fall / BMUG Fall'96 PD-ROM.iso / Education / Math / MathPad 2.4 / Examples / Poisson < prev    next >
Text File  |  1996-03-25  |  834b  |  32 lines

  1. -- Generate Poisson random inter-event times.
  2. -- Since the Poisson distribution is a simple exponential, the inverse of its integral can be used to transform the uniform random distribution.
  3.  
  4. poissonrand(aveper) = -ln(rand(1))*aveper
  5.  
  6. -- Check the distribution by accumulating a histogram.
  7. include ":incl:histogram" -- Or use "histogram" XFun
  8.  
  9. -- make an array of random inter-event times
  10. nevents = 600
  11. aveper = 2.5
  12. dt[i] = poissonrand(aveper) dim[nevents]
  13.  
  14. -- accumulate a histogram of number of events vs. inter-event time.
  15. nbins = 40
  16. histo(dt,Xmin,Xmax,nbins):
  17. --histogram(dt,Xmin,Xmax,nbins) --XFun
  18.  
  19. plot bins
  20. label mean:2.456
  21. label aveper:2.500
  22. Xmin=0; Xmax=5*aveper
  23. Ymin=0;
  24.  
  25. -- plot the continuous Poisson distribution
  26. poisson(t) = exp(-t/aveper)
  27.  
  28. plot bin1*poisson(X)
  29.  
  30. bint = (Xmax-Xmin)/nbins
  31. bin1 = nevents*(1-poisson(bint))
  32.